/* HEADER */

%{
#include <stdio.h>
#include <string.h>
#include "hw2.tab.h"

#define FLEX_DEBUG 0

int labelFunction();
int parameterVariableFunction();
int stringLiteralFunction();
int reservedWordFunction();
%}

 /* DEFINITIONS */

 /* NAME [regex] */

 /* none used */
EOL	[\r\n|\r]

%%

 /* Rules Section */
 /* Must begin comment line with a space (WTF?) */
 /* regex here */		/* action (in C) here */
[[:alnum:]_-]+			return labelFunction();
$[0-9]					return parameterVariableFunction();
\"[^\"]*\"				return stringLiteralFunction();
;[^\r\n]*			return commentFunction();
#first|#rest|#append    return reservedWordFunction();
#isequal|#echo|#input	return reservedWordFunction();
#exit					return reservedWordFunction();

 /* special symbols */
:						return COLON;
\(						return OPEN_PAREN;
\)						return CLOSE_PAREN;
[ \t\r\n]+              /* ignore whitespace */;

%%

 /* USER CODE */

int labelFunction()
{
	if (FLEX_DEBUG) printf("-LABEL:%s\n", yytext);
	yylval.string=strdup(yytext);
	return LABEL;
}

int parameterVariableFunction()
{
	if (FLEX_DEBUG) printf("-PARAMETER_VARIABLE:%s\n", yytext);
	yylval.string=strdup(yytext);
	return PARAMETER_VARIABLE;
}

int stringLiteralFunction()
{
	if (FLEX_DEBUG) printf("-STRING_LITERAL:%s\n",yytext);
	yylval.string=strdup(yytext);
	return STRING_LITERAL;
}

int reservedWordFunction()
{
	if (FLEX_DEBUG) printf("-RESERVED_WORD:%s\n", yytext);
	yylval.string=strdup(yytext);
	return RESERVED_WORD;
}

int commentFunction()
{
	if (FLEX_DEBUG) printf("-COMMENT:%s\n", yytext);
	return COMMENT;
}
